def prime_num(z):
    for i in range(2, int(a ** 0.5) + 1):
        if z % i == 0:
            return 0
a = int(input())
s = a // 1000
d = a // 100 % 10
f = a % 100 // 10
g = a % 10
if a <= 999 or a >= 10000:
    print(0)
elif prime_num(a) == 0:
    if prime_num(s * 100 + d * 10 + f) == 0:
        if prime_num(s * 10 + d) == 0:
            if prime_num(s) == 0 or s == 1:
                print(0)
            else:
                print(s)
        else:
            print(s * 10 + d)
    else:
        print(s * 100 + d * 10 + f)
else:
    print(a)